package com.example.basic.web.controller.transTask;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.model.remains.RemainsInfo;
import com.example.basic.web.request.InterveneTaskRequest;
import com.example.basic.web.response.TaskRemainsResponse;
import com.example.basic.web.service.transTask.TransTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;


@Api(value = "调度任务", tags = {"调度任务"})
@RestController
@RequestMapping("/api/v1/byg/transTask")
public class TransTaskController {

    @Resource
    private TransTaskService transTaskService;

    //执行任务链
    @Log(title = "调度任务", description = "调度指令下发")
    @ApiOperation(value = "调度指令下发", notes = "调度指令下发")
    @PostMapping("/sendTransTask")
    public Result sendTransTask(
            @ApiParam(name = "documentNo", value = "任务链") @RequestParam String documentNo) throws IOException {
        return ResultGenerator.genSuccessResult(transTaskService.sendTransTask(documentNo));
    }

    @Log(title = "调度任务", description = "直接完成")
    @ApiOperation(value = "直接完成", notes = "直接完成")
    @PostMapping("/taskFinish")
    public Result taskFinish(
            @ApiParam(name = "documentNo", value = "单据号") @RequestParam(required = true) String documentNo) throws IOException {
        return ResultGenerator.genSuccessResult(transTaskService.taskFinish(documentNo));
    }

    @Log(title = "调度任务", description = "流程干预")
    @ApiOperation(value = "流程干预", notes = "流程干预")
    @PostMapping("/interveneTask")
    public Result interveneTask(@RequestBody InterveneTaskRequest interveneTaskRequest) throws IOException {
        return ResultGenerator.genSuccessResult(transTaskService.interveneTask(interveneTaskRequest));
    }

    @Log(title = "调度任务", description = "遗体信息列表")
    @ApiOperation(value = "遗体信息列表", notes = "遗体信息列表")
    @PostMapping("/remainsTaskList")
    public Result<IPage<TaskRemainsResponse>> remainsTaskList(
            @ApiParam(name = "searchParam", value = "模糊搜索(拼音码,五笔码,名称)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "sex", value = "性别 0-全部") @RequestParam(defaultValue = "0") String sex,
            @ApiParam(name = "cremation", value = "火化方式 0-全部") @RequestParam(defaultValue = "0") String cremation,
            @ApiParam(name = "page", value = "页数，list分页的第几页") @RequestParam(defaultValue = "0") Integer page,
            @ApiParam(name = "size", value = "条数，list分页的每页条数") @RequestParam(defaultValue = "0") Integer size) {
        return ResultGenerator.genSuccessResult(transTaskService.remainsTaskList(searchParam,sex,cremation,page,size));
    }
}

